<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>状态提升</title>
</head>

<body>
    <h1>状态提升</h1>
    <hr />
    <div id="demoReact"></div>
</body>
<script src="../../node_modules/babel-standalone/babel.min.js"></script>
<script src="../../node_modules/react/umd/react.development.js"></script>
<script src="../../node_modules/react-dom/umd/react-dom.development.js"></script>
<script type="text/babel">

    // 父组件
    class MyCom extends React.Component {

        constructor() {
            super();
            this.state = {
                text: ""
            }

        }

        handleSubInput = (value) => {
            this.setState({ text: value })
        }

        render() {
            return (
                <div>    
                    <MySubA fun={this.handleSubInput} />
                    <MySubB text={this.state.text} />
                </div>
            )
        }
    }

    // 文本框组件
    class MySubA extends React.Component {

        constructor(props) {
            super(props);
        }

        handleInput(value) {
            console.log("value = ", value);
            this.props.fun(value);
        }


        render() {
            return (
                <input onInput={(e) => this.handleInput(e.currentTarget.value)} />
            )
        }
    }

    // 展示值的组件
    class MySubB extends React.Component {

        constructor(props) {
            super(props);
        }

        render() {
            return (
                <p>值：{this.props.text}</p>
            )
        }
    }

    let com = (
        <div>
            <MyCom />
        </div>
    )

    // 创建根节点
    let root = ReactDOM.createRoot(document.getElementById("demoReact"));

    // 渲染组件
    root.render(com);
</script>

</html>